Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 744)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 13.02731 13.02382 13.02039 13.01701 13.01368 13.01039 13.00714 13.00394
## [9] 13.00077 12.99764 12.99454 12.99147 12.98843 12.98542 12.98243 12.97946
## [17] 12.97651 12.97357 12.97064 12.96773 12.96482 12.96192 12.95902 12.95613
## [25] 12.95323 12.95032 12.94741 12.94449 12.94155 12.93860 12.93564 12.93265
## [33] 12.92964 12.92661 12.92355 12.92046 12.91734 12.91418 12.91100 12.90780
## [41] 12.90458 12.90135 12.89810 12.89485 12.89160 12.88834 12.88509 12.88185
## [49] 12.87862 12.87541 12.87222 12.86906 12.86592 12.86281 12.85974 12.85671
## [57] 12.85373 12.85079 12.84790 12.84507 12.84230 12.83959 12.83695 12.83437
## [65] 12.83188 12.82946 12.82713 12.82488 12.82272 12.82066 12.81869 12.81683
## [73] 12.81507 12.81342 12.81189 12.81047 12.80918 12.80801 12.80679 12.80536
## [81] 12.80372 12.80189 12.79989 12.79773 12.79542 12.79299 12.79043 12.78777
## [89] 12.78501 12.78219 12.77930 12.77636 12.77339 12.77040 12.76741 12.76442
## [97] 12.76146 12.75854 12.75566 12.75285 12.75013 12.74749 12.74496 12.74256
## [105] 12.74029 12.73817 12.73621 12.73443 12.73285 12.73147 12.73031 12.72939
## [113] 12.72871 12.72830 12.72817 12.72832 12.72879 12.72957 12.73068 12.73214
## [121] 12.73423 12.73717 12.74090 12.74537 12.75053 12.75631 12.76266 12.76952
## [129] 12.77683 12.78455 12.79261 12.80096 12.80953 12.81828 12.82714 12.83606
## [137] 12.84499 12.85386 12.86262 12.87122 12.87959 12.88768 12.89544 12.90280
## [145] 12.90971 12.91612 12.92196 12.92877 12.93794 12.94924 12.96240 12.97718
## [153] 12.99333 13.01061 13.02876 13.04753 13.06667 13.08595 13.10509 13.12386
## [161] 13.14202 13.15930 13.17545 13.19024 13.20341 13.21471 13.22390 13.23072
## [169] 13.23673 13.24359 13.25122 13.25953 13.26843 13.27783 13.28764 13.29776
## [177] 13.30812 13.31862 13.32917 13.33968 13.35007 13.36024 13.37011 13.37958
## [185] 13.38857 13.39698 13.40473 13.41173 13.41789 13.42312 13.42733 13.43043
## [193] 13.43233 13.43295 13.43219 13.42996 13.42617 13.42074 13.41350 13.40442
## [201] 13.39364 13.38130 13.36753 13.35247 13.33625 13.31900 13.30087 13.28199
## [209] 13.26249 13.24251 13.22219 13.20165 13.18104 13.16048 13.14012 13.12010
## [217] 13.10054 13.08157 13.06335 13.04338 13.01939 12.99183 12.96117 12.92786
## [225] 12.89234 12.85508 12.81652 12.77714 12.73736 12.69767 12.65850 12.62031
## [233] 12.58355 12.54869 12.51617 12.48646 12.45999 12.43724 12.41613 12.39436
## [241] 12.37205 12.34929 12.32619 12.30284 12.27936 12.25584 12.23239 12.20911
## [249] 12.18610 12.16347 12.14131 12.11974 12.09886 12.07876 12.05955 12.04134
## [257] 12.02422 12.00830 11.99368 11.98103 11.97080 11.96275 11.95667 11.95234
## [265] 11.94952 11.94800 11.94755 11.94795 11.94898 11.95041 11.95202 11.95358
## [273] 11.95487 11.95567 11.95575 11.95489 11.95287 11.94946 11.94444 11.93759
## [281] 11.93019 11.92361 11.91776 11.91256 11.90792 11.90374 11.89994 11.89643
## [289] 11.89312 11.88993 11.88675 11.88350 11.88010 11.87646 11.87248 11.86807
## [297] 11.86315 11.85763 11.85142 11.84443 11.83657 11.82764 11.81759 11.80654
## [305] 11.79461 11.78193 11.76862 11.75481 11.74062 11.72617 11.71159 11.69701
## [313] 11.68254 11.66831 11.65444 11.64106 11.62830 11.61627 11.60510 11.59492
## [321] 11.58584 11.57799 11.56938 11.55814 11.54458 11.52903 11.51181 11.49323
## [329] 11.47361 11.45328 11.43255 11.41174 11.39118 11.37117 11.35204 11.33411
## [337] 11.31770 11.30313 11.29071 11.28077 11.27363 11.26960 11.26901 11.27072
## [345] 11.27339 11.27699 11.28149 11.28686 11.29306 11.30007 11.30786 11.31640
## [353] 11.32566 11.33561 11.34622 11.35745 11.36929 11.38170 11.39465 11.40811
## [361] 11.42205 11.43644 11.45126 11.46646 11.48377 11.50471 11.52896 11.55620
## [369] 11.58611 11.61837 11.65266 11.68866 11.72606 11.76453 11.80376 11.84343
## [377] 11.88321 11.92280 11.96186 12.00008 12.03715 12.07273 12.10653 12.13820
## [385] 12.16744 12.19393 12.21734 12.24081 12.26738 12.29665 12.32820 12.36164
## [393] 12.39654 12.43249 12.46910 12.50593 12.54259 12.57867 12.61374 12.64741
## [401] 12.67927 12.70889 12.73587 12.75980 12.78028 12.79688 12.81116 12.82493
## [409] 12.83818 12.85089 12.86304 12.87462 12.88561 12.89600 12.90576 12.91489
## [417] 12.92337 12.93117 12.93829 12.94471 12.95041 12.95538 12.95960 12.96305
## [425] 12.96572 12.96760 12.96866 12.96769 12.96369 12.95693 12.94769 12.93623
## [433] 12.92284 12.90779 12.89135 12.87381 12.85543 12.83649 12.81727 12.79804
## [441] 12.77907 12.76065 12.74305 12.72653 12.71139 12.69789 12.68630 12.67691
## [449] 12.66750 12.65582 12.64212 12.62664 12.60960 12.59125 12.57182 12.55155
## [457] 12.53068 12.50944 12.48808 12.46682 12.44591 12.42558 12.40608 12.38763
## [465] 12.37047 12.35485 12.34099 12.32914 12.31954 12.31072 12.30114 12.29094
## [473] 12.28021 12.26908 12.25767 12.24609 12.23445 12.22287 12.21147 12.20036
## [481] 12.18966 12.17949 12.16996 12.16118 12.15328 12.14637 12.14057 12.13598
## [489] 12.13274 12.13095 12.13066 12.13179 12.13421 12.13784 12.14255 12.14824
## [497] 12.15480 12.16212 12.17010 12.17862 12.18759 12.19688 12.20639 12.21602
## [505] 12.22565 12.23518 12.24450 12.25350 12.26208 12.27011 12.27751 12.28596
## [513] 12.29708 12.31059 12.32624 12.34377 12.36290 12.38339 12.40496 12.42736
## [521] 12.45032 12.47359 12.49689 12.51997 12.54256 12.56441 12.58524 12.60480
## [529] 12.62283 12.63907 12.65324 12.66510 12.67437 12.68079 12.68602 12.69181
## [537] 12.69809 12.70476 12.71176 12.71899 12.72638 12.73384 12.74130 12.74867
## [545] 12.75587 12.76282 12.76943 12.77563 12.78133 12.78646 12.79092 12.79465
## [553] 12.79755 12.79954 12.80055 12.80049 12.79929 12.79685 12.79310 12.78795
## [561] 12.78133 12.77315 12.76250 12.74874 12.73218 12.71317 12.69201 12.66904
## [569] 12.64458 12.61895 12.59248 12.56549 12.53830 12.51125 12.48465 12.45883
## [577] 12.43412 12.41083 12.38930 12.36984 12.35279 12.33496 12.31324 12.28804
## [585] 12.25979 12.22889 12.19578 12.16085 12.12454 12.08726 12.04943 12.01146
## [593] 11.97377 11.93678 11.90090 11.86656 11.83417 11.80415 11.77691 11.75287
## [601] 11.73245 11.71607 11.70187 11.68775 11.67376 11.65997 11.64642 11.63318
## [609] 11.62030 11.60783 11.59584 11.58437 11.57349 11.56325 11.55371 11.54491
## [617] 11.53693 11.52981 11.52361 11.51838 11.51419 11.51108 11.50912 11.50903
## [625] 11.51136 11.51592 11.52251 11.53093 11.54099 11.55249 11.56524 11.57903
## [633] 11.59368 11.60899 11.62475 11.64078 11.65687 11.67284 11.68848 11.70360
## [641] 11.71800 11.73149 11.74387 11.75493 11.76681 11.78148 11.79859 11.81776
## [649] 11.83863 11.86082 11.88397 11.90772 11.93168 11.95550 11.97880 12.00122
## [657] 12.02239 12.04193 12.05949 12.07469 12.08880 12.10330 12.11816 12.13332
## [665] 12.14876 12.16442 12.18027 12.19626 12.21236 12.22852 12.24470 12.26085
## [673] 12.27694 12.29293 12.30877 12.32442 12.33984 12.35499 12.36983 12.38431
## [681] 12.39839 12.41204 12.42521 12.43785 12.44993 12.46141 12.47253 12.48357
## [689] 12.49452 12.50537 12.51612 12.52677 12.53730 12.54771 12.55799 12.56815
## [697] 12.57817 12.58805 12.59778 12.60735 12.61677 12.62602 12.63510 12.64400
## [705] 12.65272 12.66125 12.66958 12.67775 12.68580 12.69371 12.70149 12.70914
## [713] 12.71665 12.72402 12.73125 12.73834 12.74528 12.75208 12.75872 12.76522
## [721] 12.77156 12.77774 12.78377 12.78963 12.79534 12.80087 12.80625 12.81145
## [729] 12.81647 12.82130 12.82594 12.83040 12.83467 12.83877 12.84270 12.84646
## [737] 12.85006 12.85350 12.85678 12.85991 12.86289 12.86573 12.86842 12.87098
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 744)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.63127 12.62643 12.62168 12.61704 12.61249 12.60804 12.60369 12.59943
## [9] 12.59526 12.59118 12.58720 12.58330 12.57948 12.57575 12.57211 12.56854
## [17] 12.56505 12.56165 12.55832 12.55506 12.55188 12.54877 12.54573 12.54275
## [25] 12.53985 12.53701 12.53423 12.53152 12.52887 12.52628 12.52374 12.52126
## [33] 12.51884 12.51647 12.51414 12.51187 12.50965 12.50746 12.50532 12.50323
## [41] 12.50119 12.49920 12.49726 12.49539 12.49357 12.49182 12.49014 12.48852
## [49] 12.48698 12.48551 12.48411 12.48280 12.48157 12.48043 12.47937 12.47841
## [57] 12.47753 12.47676 12.47608 12.47551 12.47503 12.47467 12.47442 12.47428
## [65] 12.47425 12.47434 12.47455 12.47489 12.47535 12.47594 12.47666 12.47752
## [73] 12.47851 12.47965 12.48092 12.48234 12.48391 12.48563 12.48752 12.48958
## [81] 12.49182 12.49423 12.49680 12.49954 12.50243 12.50548 12.50867 12.51200
## [89] 12.51548 12.51908 12.52282 12.52668 12.53066 12.53476 12.53897 12.54328
## [97] 12.54770 12.55222 12.55683 12.56152 12.56631 12.57117 12.57611 12.58111
## [105] 12.58619 12.59132 12.59652 12.60176 12.60706 12.61240 12.61777 12.62319
## [113] 12.62863 12.63410 12.63959 12.64509 12.65061 12.65614 12.66166 12.66719
## [121] 12.67292 12.67903 12.68549 12.69225 12.69929 12.70656 12.71402 12.72164
## [129] 12.72938 12.73721 12.74507 12.75295 12.76080 12.76857 12.77625 12.78378
## [137] 12.79113 12.79827 12.80514 12.81173 12.81799 12.82388 12.83091 12.84046
## [145] 12.85226 12.86606 12.88160 12.89861 12.91684 12.93603 12.95592 12.97625
## [153] 12.99676 13.01720 13.03730 13.05680 13.07545 13.09298 13.10914 13.12367
## [161] 13.13631 13.14680 13.15488 13.16210 13.17014 13.17891 13.18834 13.19833
## [169] 13.20882 13.21972 13.23095 13.24243 13.25407 13.26581 13.27755 13.28921
## [177] 13.30072 13.31199 13.32295 13.33350 13.34358 13.35310 13.36198 13.37013
## [185] 13.37748 13.38395 13.38946 13.39392 13.39725 13.39937 13.40021 13.39968
## [193] 13.39770 13.39419 13.38907 13.38225 13.37295 13.36061 13.34550 13.32789
## [201] 13.30805 13.28625 13.26277 13.23788 13.21185 13.18494 13.15744 13.12962
## [209] 13.10174 13.07407 13.04690 13.02048 12.99510 12.97101 12.94851 12.92785
## [217] 12.90931 12.88967 12.86592 12.83865 12.80844 12.77589 12.74157 12.70607
## [225] 12.66999 12.63389 12.59838 12.56403 12.53143 12.50117 12.47383 12.45000
## [233] 12.43027 12.41236 12.39369 12.37438 12.35454 12.33427 12.31369 12.29292
## [241] 12.27206 12.25123 12.23053 12.21009 12.19002 12.17041 12.15140 12.13309
## [249] 12.11559 12.09901 12.08348 12.06909 12.05596 12.04421 12.03450 12.02729
## [257] 12.02235 12.01944 12.01833 12.01880 12.02061 12.02354 12.02735 12.03182
## [265] 12.03671 12.04179 12.04684 12.05162 12.05591 12.05946 12.06206 12.06348
## [273] 12.06347 12.06182 12.05829 12.05469 12.05285 12.05257 12.05368 12.05596
## [281] 12.05923 12.06329 12.06796 12.07303 12.07832 12.08364 12.08878 12.09356
## [289] 12.09778 12.10125 12.10377 12.10516 12.10522 12.10376 12.10058 12.09549
## [297] 12.08877 12.08087 12.07193 12.06203 12.05129 12.03982 12.02773 12.01512
## [305] 12.00211 11.98880 11.97530 11.96172 11.94817 11.93475 11.92159 11.90877
## [313] 11.89642 11.88464 11.87354 11.86322 11.85381 11.84317 11.82936 11.81274
## [321] 11.79366 11.77250 11.74961 11.72534 11.70007 11.67415 11.64795 11.62182
## [329] 11.59612 11.57121 11.54747 11.52523 11.50488 11.48676 11.47124 11.45867
## [337] 11.44943 11.44387 11.44020 11.43644 11.43267 11.42897 11.42541 11.42207
## [345] 11.41902 11.41634 11.41410 11.41238 11.41125 11.41080 11.41109 11.41221
## [353] 11.41422 11.41720 11.42123 11.42638 11.43274 11.44037 11.44935 11.46058
## [361] 11.47478 11.49174 11.51122 11.53302 11.55692 11.58270 11.61016 11.63906
## [369] 11.66919 11.70035 11.73230 11.76484 11.79775 11.83081 11.86381 11.89652
## [377] 11.92874 11.96024 11.99081 12.02024 12.04830 12.07478 12.09947 12.12214
## [385] 12.14258 12.16379 12.18853 12.21629 12.24653 12.27872 12.31234 12.34686
## [393] 12.38174 12.41646 12.45048 12.48329 12.51434 12.54311 12.56908 12.59170
## [401] 12.61046 12.62764 12.64575 12.66466 12.68420 12.70422 12.72456 12.74508
## [409] 12.76561 12.78601 12.80611 12.82577 12.84482 12.86312 12.88051 12.89683
## [417] 12.91194 12.92567 12.93787 12.94839 12.95708 12.96377 12.96856 12.97171
## [425] 12.97332 12.97349 12.97234 12.96997 12.96649 12.96200 12.95661 12.95042
## [433] 12.94354 12.93607 12.92813 12.91981 12.91122 12.90248 12.89367 12.88492
## [441] 12.87632 12.86799 12.86002 12.85043 12.83741 12.82129 12.80245 12.78121
## [449] 12.75795 12.73299 12.70671 12.67944 12.65155 12.62337 12.59526 12.56757
## [457] 12.54066 12.51486 12.49055 12.46805 12.44773 12.42994 12.41502 12.40334
## [465] 12.39237 12.37953 12.36506 12.34919 12.33214 12.31416 12.29547 12.27631
## [473] 12.25690 12.23749 12.21830 12.19956 12.18152 12.16439 12.14841 12.13382
## [481] 12.12085 12.10972 12.10068 12.09394 12.08976 12.08721 12.08521 12.08376
## [489] 12.08285 12.08247 12.08262 12.08329 12.08446 12.08614 12.08831 12.09097
## [497] 12.09411 12.09772 12.10179 12.10632 12.11130 12.11671 12.12256 12.12884
## [505] 12.13553 12.14264 12.15169 12.16406 12.17949 12.19770 12.21844 12.24143
## [513] 12.26642 12.29314 12.32131 12.35068 12.38098 12.41194 12.44330 12.47479
## [521] 12.50616 12.53712 12.56742 12.59679 12.62496 12.65168 12.67667 12.69966
## [529] 12.72040 12.73862 12.75405 12.76642 12.77790 12.79069 12.80467 12.81967
## [537] 12.83556 12.85219 12.86941 12.88706 12.90502 12.92312 12.94121 12.95917
## [545] 12.97682 12.99404 13.01067 13.02656 13.04156 13.05554 13.06833 13.07981
## [553] 13.08980 13.09818 13.10479 13.10949 13.11212 13.11255 13.11062 13.10618
## [561] 13.09864 13.08775 13.07389 13.05747 13.03886 13.01847 12.99668 12.97389
## [569] 12.95047 12.92684 12.90337 12.88046 12.85849 12.83787 12.81897 12.80220
## [577] 12.78449 12.76280 12.73754 12.70911 12.67792 12.64437 12.60888 12.57185
## [585] 12.53368 12.49479 12.45558 12.41645 12.37782 12.34008 12.30365 12.26893
## [593] 12.23633 12.20626 12.17912 12.15532 12.13526 12.11561 12.09301 12.06779
## [601] 12.04032 12.01095 11.98003 11.94792 11.91496 11.88151 11.84792 11.81455
## [609] 11.78175 11.74987 11.71926 11.69028 11.66328 11.63861 11.61663 11.59768
## [617] 11.58213 11.57032 11.56117 11.55333 11.54673 11.54130 11.53700 11.53376
## [625] 11.53152 11.53021 11.52978 11.53017 11.53131 11.53315 11.53561 11.53866
## [633] 11.54221 11.54621 11.55060 11.55532 11.56031 11.56551 11.57085 11.57791
## [641] 11.58809 11.60113 11.61674 11.63463 11.65453 11.67616 11.69922 11.72345
## [649] 11.74856 11.77426 11.80028 11.82634 11.85215 11.87743 11.90189 11.92527
## [657] 11.94727 11.96762 11.98603 12.00223 12.01769 12.03406 12.05125 12.06918
## [665] 12.08778 12.10697 12.12667 12.14680 12.16729 12.18805 12.20901 12.23010
## [673] 12.25122 12.27232 12.29330 12.31408 12.33460 12.35478 12.37453 12.39377
## [681] 12.41244 12.43044 12.44771 12.46417 12.47973 12.49433 12.50847 12.52270
## [689] 12.53701 12.55138 12.56577 12.58018 12.59457 12.60892 12.62321 12.63742
## [697] 12.65152 12.66550 12.67933 12.69299 12.70645 12.71969 12.73270 12.74544
## [705] 12.75790 12.77005 12.78188 12.79348 12.80499 12.81640 12.82771 12.83890
## [713] 12.84999 12.86095 12.87178 12.88248 12.89305 12.90347 12.91375 12.92388
## [721] 12.93384 12.94365 12.95328 12.96274 12.97203 12.98113 12.99004 12.99875
## [729] 13.00723 13.01544 13.02340 13.03111 13.03860 13.04586 13.05292 13.05978
## [737] 13.06645 13.07296 13.07930 13.08549 13.09155 13.09748 13.10329 13.10900
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 744)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 12.02674 12.02154 12.01644 12.01142 12.00649 12.00164 11.99687 11.99218
## [9] 11.98756 11.98301 11.97853 11.97411 11.96976 11.96547 11.96123 11.95705
## [17] 11.95292 11.94884 11.94481 11.94082 11.93687 11.93296 11.92908 11.92524
## [25] 11.92143 11.91764 11.91388 11.91014 11.90642 11.90271 11.89902 11.89534
## [33] 11.89167 11.88800 11.88434 11.88067 11.87700 11.87333 11.86965 11.86595
## [41] 11.86224 11.85852 11.85477 11.85100 11.84721 11.84339 11.83956 11.83573
## [49] 11.83189 11.82805 11.82423 11.82042 11.81664 11.81288 11.80916 11.80548
## [57] 11.80184 11.79826 11.79474 11.79128 11.78790 11.78458 11.78136 11.77822
## [65] 11.77518 11.77223 11.76940 11.76667 11.76407 11.76159 11.75925 11.75704
## [73] 11.75497 11.75305 11.75129 11.74969 11.74826 11.74700 11.74592 11.74502
## [81] 11.74432 11.74382 11.74351 11.74342 11.74355 11.74370 11.74372 11.74362
## [89] 11.74340 11.74310 11.74272 11.74228 11.74179 11.74128 11.74076 11.74024
## [97] 11.73975 11.73929 11.73889 11.73855 11.73831 11.73816 11.73813 11.73824
## [105] 11.73849 11.73892 11.73952 11.74033 11.74135 11.74260 11.74410 11.74586
## [113] 11.74791 11.75024 11.75289 11.75587 11.75919 11.76288 11.76693 11.77139
## [121] 11.77625 11.78153 11.78726 11.79344 11.80010 11.80725 11.81575 11.82633
## [129] 11.83880 11.85298 11.86867 11.88569 11.90385 11.92296 11.94283 11.96328
## [137] 11.98410 12.00512 12.02615 12.04700 12.06748 12.08739 12.10656 12.12480
## [145] 12.14191 12.15770 12.17199 12.18733 12.20614 12.22806 12.25272 12.27976
## [153] 12.30881 12.33950 12.37147 12.40436 12.43780 12.47142 12.50486 12.53775
## [161] 12.56973 12.60043 12.62949 12.65653 12.68120 12.70314 12.72196 12.73731
## [169] 12.75111 12.76546 12.78026 12.79544 12.81090 12.82657 12.84234 12.85815
## [177] 12.87389 12.88948 12.90484 12.91988 12.93451 12.94865 12.96220 12.97509
## [185] 12.98722 12.99851 13.00887 13.01822 13.02646 13.03352 13.03929 13.04371
## [193] 13.04668 13.04811 13.04792 13.04602 13.04232 13.03674 13.02837 13.01654
## [201] 13.00157 12.98376 12.96340 12.94080 12.91627 12.89010 12.86261 12.83409
## [209] 12.80484 12.77517 12.74538 12.71578 12.68666 12.65833 12.63109 12.60525
## [217] 12.58110 12.55896 12.53911 12.51836 12.49358 12.46525 12.43385 12.39983
## [225] 12.36368 12.32586 12.28685 12.24710 12.20711 12.16732 12.12823 12.09029
## [233] 12.05397 12.01976 11.98811 11.95950 11.93440 11.91328 11.89447 11.87597
## [241] 11.85780 11.83994 11.82239 11.80516 11.78823 11.77161 11.75529 11.73927
## [249] 11.72355 11.70812 11.69299 11.67815 11.66360 11.64933 11.63534 11.62164
## [257] 11.60822 11.59507 11.58219 11.57062 11.56126 11.55390 11.54833 11.54434
## [265] 11.54174 11.54030 11.53983 11.54012 11.54096 11.54215 11.54347 11.54473
## [273] 11.54571 11.54621 11.54602 11.54493 11.54274 11.53925 11.53423 11.52750
## [281] 11.52025 11.51380 11.50806 11.50295 11.49841 11.49434 11.49068 11.48733
## [289] 11.48424 11.48131 11.47847 11.47564 11.47275 11.46971 11.46644 11.46288
## [297] 11.45894 11.45454 11.44960 11.44406 11.43782 11.43004 11.42010 11.40822
## [305] 11.39463 11.37956 11.36326 11.34594 11.32785 11.30920 11.29025 11.27121
## [313] 11.25232 11.23382 11.21593 11.19888 11.18292 11.16827 11.15515 11.14382
## [321] 11.13449 11.12740 11.12056 11.11198 11.10190 11.09054 11.07814 11.06493
## [329] 11.05113 11.03698 11.02272 11.00856 10.99475 10.98151 10.96908 10.95769
## [337] 10.94756 10.93893 10.93203 10.92710 10.92436 10.92404 10.92637 10.93122
## [345] 10.93820 10.94713 10.95785 10.97022 10.98406 10.99922 11.01554 11.03285
## [353] 11.05099 11.06981 11.08915 11.10884 11.12872 11.14863 11.16842 11.18792
## [361] 11.20697 11.22541 11.24308 11.25982 11.27745 11.29770 11.32036 11.34519
## [369] 11.37193 11.40036 11.43024 11.46133 11.49339 11.52619 11.55948 11.59303
## [377] 11.62660 11.65996 11.69285 11.72506 11.75633 11.78643 11.81513 11.84218
## [385] 11.86735 11.89039 11.91108 11.93141 11.95342 11.97685 12.00147 12.02706
## [393] 12.05336 12.08016 12.10721 12.13427 12.16113 12.18752 12.21323 12.23802
## [401] 12.26165 12.28389 12.30450 12.32324 12.33989 12.35420 12.36729 12.38039
## [409] 12.39344 12.40640 12.41922 12.43184 12.44420 12.45627 12.46798 12.47928
## [417] 12.49012 12.50046 12.51023 12.51939 12.52789 12.53566 12.54267 12.54885
## [425] 12.55416 12.55855 12.56195 12.56378 12.56356 12.56147 12.55768 12.55237
## [433] 12.54570 12.53785 12.52898 12.51928 12.50890 12.49803 12.48684 12.47549
## [441] 12.46415 12.45301 12.44223 12.43198 12.42244 12.41377 12.40615 12.39974
## [449] 12.39306 12.38460 12.37454 12.36306 12.35032 12.33650 12.32177 12.30631
## [457] 12.29030 12.27390 12.25730 12.24066 12.22416 12.20798 12.19228 12.17724
## [465] 12.16304 12.14986 12.13785 12.12721 12.11810 12.10904 12.09857 12.08685
## [473] 12.07406 12.06037 12.04597 12.03102 12.01570 12.00019 11.98466 11.96928
## [481] 11.95423 11.93969 11.92583 11.91283 11.90086 11.89009 11.88070 11.87287
## [489] 11.86677 11.86258 11.85950 11.85665 11.85406 11.85173 11.84971 11.84800
## [497] 11.84664 11.84564 11.84504 11.84484 11.84508 11.84578 11.84696 11.84865
## [505] 11.85086 11.85363 11.85696 11.86090 11.86545 11.87065 11.87652 11.88408
## [513] 11.89423 11.90671 11.92130 11.93775 11.95585 11.97535 11.99602 12.01762
## [521] 12.03992 12.06269 12.08569 12.10870 12.13146 12.15376 12.17535 12.19601
## [529] 12.21550 12.23358 12.25002 12.26459 12.27705 12.28716 12.29678 12.30779
## [537] 12.32008 12.33349 12.34789 12.36315 12.37914 12.39571 12.41274 12.43008
## [545] 12.44761 12.46518 12.48266 12.49992 12.51681 12.53321 12.54898 12.56398
## [553] 12.57808 12.59114 12.60302 12.61360 12.62273 12.63028 12.63612 12.64011
## [561] 12.64211 12.64199 12.63974 12.63556 12.62963 12.62213 12.61323 12.60310
## [569] 12.59193 12.57989 12.56715 12.55389 12.54029 12.52652 12.51275 12.49918
## [577] 12.48596 12.47328 12.46131 12.45023 12.44022 12.42887 12.41392 12.39573
## [585] 12.37466 12.35107 12.32532 12.29778 12.26880 12.23874 12.20798 12.17685
## [593] 12.14574 12.11500 12.08498 12.05606 12.02859 12.00294 11.97945 11.95851
## [601] 11.94046 11.92567 11.91207 11.89745 11.88198 11.86580 11.84906 11.83191
## [609] 11.81451 11.79700 11.77954 11.76229 11.74538 11.72898 11.71323 11.69829
## [617] 11.68431 11.67144 11.65982 11.64963 11.64099 11.63407 11.62902 11.62592
## [625] 11.62465 11.62508 11.62705 11.63044 11.63509 11.64086 11.64761 11.65520
## [633] 11.66349 11.67233 11.68158 11.69110 11.70075 11.71038 11.71985 11.72902
## [641] 11.73774 11.74588 11.75329 11.75983 11.76712 11.77667 11.78819 11.80139
## [649] 11.81596 11.83162 11.84807 11.86501 11.88215 11.89920 11.91585 11.93181
## [657] 11.94679 11.96050 11.97262 11.98288 11.99242 12.00254 12.01319 12.02430
## [665] 12.03583 12.04771 12.05988 12.07229 12.08488 12.09760 12.11038 12.12317
## [673] 12.13590 12.14853 12.16100 12.17324 12.18521 12.19683 12.20806 12.21884
## [681] 12.22911 12.23881 12.24789 12.25629 12.26394 12.27080 12.27724 12.28370
## [689] 12.29013 12.29654 12.30290 12.30918 12.31538 12.32148 12.32746 12.33329
## [697] 12.33897 12.34447 12.34977 12.35487 12.35973 12.36434 12.36869 12.37275
## [705] 12.37650 12.37994 12.38304 12.38589 12.38860 12.39115 12.39356 12.39580
## [713] 12.39788 12.39979 12.40152 12.40307 12.40444 12.40562 12.40661 12.40740
## [721] 12.40798 12.40835 12.40850 12.40844 12.40815 12.40763 12.40687 12.40588
## [729] 12.40461 12.40302 12.40115 12.39899 12.39655 12.39385 12.39090 12.38770
## [737] 12.38427 12.38062 12.37676 12.37270 12.36845 12.36402 12.35943 12.35467
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")